package com.java.rabbitmq.worker;

import com.java.rabbitmq.util.ConnectionUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

/**
 * @author Woo_home
 * @create 2020/5/26 13:06
 */

public class ProducerDemo {

    /**
     * F ---> Queue ---> C1,C2
     * @param args
     * @throws Exception
     */

    // 队列名称
    private static final String QUEUE_NAME = "test_worker_queue";

    public static void main(String[] args) throws Exception {

        // 获取连接
        Connection connection = ConnectionUtils.getConnection();

        // 获取 Channel
        Channel channel = connection.createChannel();

        // 声明队列
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);

        // 往队列里面发送
        for (int i = 0; i < 50; i++) {
            String msg = "Hello RabbitMQ " + i;
            channel.basicPublish("", QUEUE_NAME, null, msg.getBytes());
            System.out.println("send msg : " + msg);
            Thread.sleep(i * 20);
        }

        // 关闭资源
        channel.close();
        connection.close();
    }
}
